/*
 * Copyright © 2020-present LiuDanYang. All rights Reserved.
 */

// 项目名
const STORAGE_NAME = "CGJ_GD";

/**
 * @param name
 * @param data
 */
export function setStorage(name, data) {
	const key = STORAGE_NAME + name;
	uni.setStorageSync(key, data);
}

/**
 * @param name
 * @returns {null|any}
 */
export function getStorage(name) {
	const key = STORAGE_NAME + name;
	const data = uni.getStorageSync(key);
	return data ? data : null;
}

/**
 * 删除数据
 * @param name
 */
export function removeStorage(name) {
	const key = STORAGE_NAME + name;
	uni.removeStorageSync(key);
}

// token
const t = "_T";

export function getToken() {
	return getStorage(t);
}

export function setToken(data) {
	return setStorage(t, data);
}

export function removeToken() {
	return removeStorage(t);
}

// 微信openid
const OpenKey = "_W";

export function getWeChatAuth() {
	return getStorage(OpenKey);
}

export function setWeChatAuth(data) {
	return setStorage(OpenKey, data);
}

export function removeWeChatAuth() {
	return removeStorage(OpenKey);
}

const user = "_U";

// 获取用户信息
export function getLocalUserInfo() {
	return getStorage(user);
}

// 设置用户信息
export function setLocalUserInfo(data) {
	return setStorage(user, data);
}

// 移除用户信息
export function removeLocalUserInfo() {
	return removeStorage(user);
}